package com.wd.live.view;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;

import android.os.Bundle;
import android.view.View;

import com.wd.live.R;
import com.wd.live.base.BaseActivity;
import com.wd.live.base.BaseViewModel;
import com.wd.live.bean.OverBDBean;
import com.wd.live.bean.SeeBDBean;
import com.wd.live.databinding.ActivitySeeBDBinding;
import com.wd.live.model.utils.ToastFormat;
import com.wd.live.viewmodel.SeeBDViewModel;

import java.util.List;

public class SeeBDActivity extends BaseActivity<SeeBDViewModel, ActivitySeeBDBinding> {



    @Override
    protected void initData() {
        viewmodel.getList().observe(this, new Observer<SeeBDBean>() {
            @Override
            public void onChanged(SeeBDBean seeBDBean) {
                List<SeeBDBean.ResultBean> result = seeBDBean.getResult();
                for (SeeBDBean.ResultBean resultBean : result) {
                    databind.bdbank.setText(resultBean.getName());
                    String s = hideId(resultBean.getCardNumber());
                    databind.bdbankcard.setText(s);

                    databind.BDnum.setText(resultBean.getCardNumber());
                    databind.BDname.setText(resultBean.getAccountName());
                    databind.jiebang.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            viewmodel.getList2(resultBean.getCardNumber()).observe(SeeBDActivity.this, new Observer<OverBDBean>() {
                                @Override
                                public void onChanged(OverBDBean overBDBean) {
                                    ToastFormat.setText(overBDBean.getMessage());
                                    ToastFormat.show();
                                    if(overBDBean.getStatus().equals("0000")){
                                        finish();
                                    }
                                }
                            });
                        }
                    });
                }
            }
        });


    }

    @Override
    protected int initLayout() {
        return R.layout.activity_see_b_d;
    }

    @Override
    public void onChanged(Object o) {

    }
    public static String hideId(String id) {
        String idNum = id.replaceAll("(\\d{4})\\d{11}(\\d{4})", "$1 **** **** $2");
        return idNum;
    }

}